PHPとSQL Anywhereでメタ情報を使用する

 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
 
    #*********************************************************************     
    # Description:
    # It is also possible to retrieve meta information about results.
    # sasql_fetch_field() returns an object that contains column
    # properties of a result set.
    #
    # The sample code fetches meta information about a result using
    # sasql_fetch_field() and fetches the row using sasql_fetch_row().
    #
    #*********************************************************************
 
    # Connect using the default user ID and password
    $conn =sasql_connect ( "UID=DBA;PWD=sql" ) ;
    if ( ! $conn ) {
        die ( "Connection failed" ) ;
    } else {
        # Connected successfully.
        # Execute a SELECT statement
        $result =sasql_query ( $conn , "SELECT * FROM Customers" ) ;
        if ( ! $result ) {
          echo "sasql_query failed!" ;
          return 0 ;
        } else {
          echo "query completed successfully \n " ;
        }
        # Retrieve meta information about the results
        $num_cols =sasql_num_fields ( $result ) ;
        $num_rows =sasql_num_rows ( $result ) ;
        echo "Num of rows = $num_rows \n " ;
        echo "Num of cols = $num_cols \n " ;
        while ( ( $field =sasql_fetch_field ( $result ) ) ) {
          echo "Field # : $field->id \n " ;
          echo " \t name : $field->name \n " ;
          echo " \t length : $field->length \n " ;
          echo " \t type : $field->type \n " ;
        }
        # Fetch all the rows
        $curr_row = 0 ;
        while ( ( $row =sasql_fetch_row ( $result ) ) ) {
          $curr_row ++;
          $curr_col = 0 ;
          while ( $curr_col < $num_cols ) {
              echo "$row[$curr_col] \t |" ;
              $curr_col ++;
          }
          echo " \n " ;
        }
        # Clean up.
       sasql_free_result ( $result ) ;
       sasql_disconnect ( $conn ) ;
    }
 
?>

Copyright 2011 iAnywhere Solutions, Inc. All rights reserved. This sample code is provided AS IS, without warranty or liability of any kind.


BACK : 技術情報(サンプルコード&ユーティリティ)のトップページ
 
このウインドウを閉じる
 
Copyright 2011 iAnywhere Solutions K.K.